package com.qianya.oa.controller.activiti;

import com.qianya.oa.common.core.controller.BaseController;
import com.qianya.oa.common.core.domain.entity.SysUser;
import com.qianya.oa.dto.FormSubmitParam;
import com.qianya.oa.service.FormInstDataService;
import com.qianya.oa.service.FormInstService;
import com.qianya.oa.util.CommonResult;
import com.qianya.oa.vo.FormVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "表单接口")
@RestController
@RequestMapping("/form/inst")
public class FormInstController extends BaseController {

    @Resource
    private FormInstService formInstService;


    /**
     * 获取表单实例数据
     */
    @ApiOperation("获取表单实例数据")
    @GetMapping("/get")
    public FormVo get(@RequestParam("processInstanceId") String processInstanceId, @RequestParam("formKey") String formKey) {
        return formInstService.get(processInstanceId, formKey);
    }

    /**
     * 提交表单实例
     */
    @ApiOperation("提交表单实例")
    @PostMapping("/submit")
    public CommonResult submit(@RequestBody FormSubmitParam formSubmitParam) {
        SysUser user = getSysUser();
        String s = formInstService.submit(user, formSubmitParam);
        if (s != null) {
            return CommonResult.erro(s);
        } else {
            return CommonResult.success();
        }
    }


}
